Exporting Users to excel

Hello, How can I export the users into an excel / .csv format?

Hi Sumit,

We don’t currently have a way to export the users of an account. We do have an existing Feature Request for this and I’ll add your vote.

Thanks,
Abbott
Support Team Lead - East Coast

We use this to get Users via the API to create a csv file.

Get PagerDuty Licenses.ps1

API Token Numbers

$APIToken = "Intentionally Removed"

Reset Variables

$OffsetVal = 0
$val = 0
$Output = @()

#Get Total Records
$URL = “https://api.pagerduty.com/users?offset=0&total=true&limit=1

$headers = @{
    "Authorization" ="Token token=$APIToken"
    "Accept"="application/vnd.pagerduty+json;version=2"
}
    $ResponseUserID = Invoke-RestMethod -Method GET -Uri $URL -Header $headers -UseBasicParsing
    $TotalRecords = New-Object -TypeName psobject -Property @{More=$($ResponseUserID.total)}

#Loop through records until Total Records is Reached
Do {

    # Set Offset
    if($val-ge 100){$OffsetVal = 100}
    if($val-ge 200){$OffsetVal = 200}
    if($val-ge 300){$OffsetVal = 300}
    if($val-ge 400){$OffsetVal = 400}
    if($val-ge 500){$OffsetVal = 500}

    #Defne URL with correct offset
    $URL = @()
    $URLa = "https://api.pagerduty.com/users?offset="
    $URLb = "&total=true&limit=100"
    $URL = $URLa+$OffsetVal+$URLb

        $ResponseUserID = Invoke-RestMethod -Method GET -Uri $URL -Header $headers -UseBasicParsing

    #Loop through each line and add to $Output
    $($ResponseUserID.users.id) | ForEach-Object{
    
        $User = Invoke-RestMethod -Method GET -Uri https://api.pagerduty.com/users/$($_) -Header $headers -UseBasicParsing

        $Output += New-Object -TypeName psobject -Property @{
            Mail="$($User.user.email)"; 
            Name="$($User.user.name)";
            Role="$($User.user.role)"}
     
            #Exit Loop when $TotalRecords.More is reached
            $ExitVal = $val - $TotalRecords.More
            if($ExitVal -eq 0){break}

        #Increment User Count    
        $val=$val+1

    }
    }while($val -ne $TotalRecords.More)

Create and put in C:\Users<LAN ID>\AppData\Roaming\Temp folder

$ExtractFolder = “$env:APPDATA\Temp”
If (!(Test-Path $ExtractFolder -PathType Container)) {New-Item -ItemType Directory -Force -Path $ExtractFolder}
$Output | Export-csv -Path $ExtractFolder\PD_Users.csv -NoTypeInformation

Invoke-item $ExtractFolder # Open Windows File Explorer to that folder

Hi all,

First: we already made a feature request, via our CSM + sales representative, to export PagerDuty resources (not only users) to external systems as it may be very useful for customers. We mentioned many examples for several customers making those exports by API, … and a out-of-the-box feature would be really useful.
NB: for us it’s BigQuery, see: https://community.pagerduty.com/forum/t/getting-only-changed-incidents/3657/3?u=sébastien.de.nef

Second: for this dedicated request (users as CSV) a simple solution is to use the PagerDuty CLI (not a PagerDuty supported tool, but it rocks :slight_smile: )


pd user:list --output=csv

Regards,
Sébastien

1 Like

This bulk user manager tool example is also useful:

1 Like

Hi, any update on this?
A request for a simple action - requested over a year ago already, any ETA?
I am sure it will be useful for many accounts.

Have you seen the pagerduty_users data source, from the pagerduty/pagerduty terraform provider ?

You could leave the output in JSON if that also works, or transform to CSV with jq or something else.

$ cat >provider.tf <<EOF
terraform {
  required_providers {
    pagerduty = {
      source  = "pagerduty/pagerduty"
    }
  }
}
EOF
$ cat >users.tf <<EOF
data "pagerduty_users" "all" {}

output "users" {
  value = data.pagerduty_users.all.users
}
EOF
$ terraform init
$ export PAGERDUTY_TOKEN=xxxxxxx
$ export PAGERDUTY_USER_TOKEN=yyyyyyy
$ terraform apply
$ terraform output -json users | jq '.'